package com.wuchaooooo.service.zjutsds.utils;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import org.apache.commons.lang3.StringUtils;

public class CommonUtils {

	public static <T> T getFieldValueByFieldName(String fieldName, Object object) {
		try {
			Method method = object.getClass().getMethod("get"+StringUtils.capitalize(fieldName));
			return (T) method.invoke(object);
		} catch (Exception e) {
			return null;
		}
	}

	public static void setFieldValueByFieldName(String fieldName, Object value, Object object) {
		try {
			Method method = object.getClass().getMethod("set"+StringUtils.capitalize(fieldName), Integer.class);
			// 设置对象的访问权限，保证对private的属性的访问
			method.invoke(object, value);
		} catch (Exception e) {
			return;
		}
	}
}
